#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
using ll = __int128_t;
using T = int;
T rad(); // quick read
const int inf = 0x3f3f3f3f;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
const int max_size = 5 + 100;
const int maxn = 5 + 1e3;

vector<ll> num;
vector<char> op;
char a[maxn];
int len;

ll cal_val(ll l, char op, ll r) {
    switch (op) {
    case '+':
        return l + r;
    case '-':
        return l - r;
    case 'x':
        return l * r;
    case '/':
        return l / r;
    }
    return inf;
}

void cal_one() {
    ll r = num.back();
    num.pop_back();
    ll l = num.back();
    num.pop_back();
    num.push_back(cal_val(l, op.back(), r));
    op.pop_back();
}

bool check(char r) { // cal now
    if (op.size() == 0) return 0;
    char l = op.back();
    if (l == 'x' || l == '/') return 1;
    if (r == '+' || r == '-') return 1;
    return 0;
}

ll get_val(char *&p) {
    ll tmp = 0;
    for (; *p != '=' && isdigit(*p); ++p)
        tmp = 10 * tmp + *p - '0';
    return tmp;
}

ll cal() {
    for (char *p = a; *p != '=';) {
        if (isdigit(*p)) {
            num.push_back(get_val(p));
            continue;
        }
        if (check(*p)) cal_one();
        op.push_back(*p);
        ++p;
    }
    while (op.size())
        cal_one();
    return num.back();
}

void init() {
    num.clear(), op.clear();
    num.push_back(0);
}

void show(ll x) {
    if (x == 0) return;
    show(x / 10);
    putchar(x % 10 + '0');
}

ostream &operator<<(ostream &cout, ll x) {
    if (x == 0) return cout << 0;
    if (x < 0) putchar('-');
    show(x < 0 ? -x : x);
    return cout;
}

int main() {
    int Q = rad();
    rf(q, Q) {
        scanf("%s", a);
        init();
        ll tmp = cal();
        cout << tmp << endl;

        // for (auto p : num)
        //     cout << p << " ";
        // for (auto p : op)
        //     cout << p << " ";
    }
}

T rad() {
    T back = 0;
    int ch = 0, posi = 0;
    for (; ch < '0' || ch > '9'; ch = getchar())
        posi = ch ^ '-';
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        back = (back << 1) + (back << 3) + (ch & 0xf);
    return posi ? back : -back;
}